/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bea.cliente.gui.controllers;

import bea.cliente.core.Memory;
import bea.cliente.core.GuiManagerState;
import bea.cliente.gui.builders.AudioOptionsWindowBuilder;
import bea.cliente.gui.builders.GraphicsOptionsWindowBuilder;
import bea.cliente.gui.builders.MainScreenBuilder;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.DropDown;
import de.lessvoid.nifty.controls.ListBox;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 *
 * @author Ivan
 */
public class MainScreenController implements ScreenController {

    private GuiManagerState guiManager;
    private Nifty nifty;
    private Screen screen;
    private Element windowsContainer;
    private Element graphicsOptionsWindow;
    private Element audioOptionsWindow;

    @Override
    public void bind(Nifty nifty, Screen screen) {
        this.guiManager = Memory.get("guiManager");
        this.nifty = nifty;
        this.screen = screen;
        // busca o container das janelas
        windowsContainer = screen.findElementByName("layerMainScreenWindowsOptions");
        graphicsOptionsWindow = GraphicsOptionsWindowBuilder.build(nifty, screen, windowsContainer);
        audioOptionsWindow = AudioOptionsWindowBuilder.build(nifty, screen, windowsContainer);

        // configura os tipos de jogos na lista
        DropDown dropDownGameType = screen.findNiftyControl(MainScreenBuilder.DDL_GAME_TYPE_ID, DropDown.class);
        dropDownGameType.addAllItems(MainScreenBuilder.GAME_TYPES);
        // configura os tamanhos de times
        DropDown dropDownTeamSize = screen.findNiftyControl(MainScreenBuilder.DDL_TEAM_SIZE_ID, DropDown.class);
        dropDownTeamSize.addAllItems(MainScreenBuilder.TEAM_SIZES);
        // configura os tipos de jogos na lista
        DropDown dropDownMaps = screen.findNiftyControl(MainScreenBuilder.DDL_MAP_ID, DropDown.class);
        dropDownMaps.addAllItems(MainScreenBuilder.MAPS);
        
        // add sample list
        addSampleList();
    }

    @Override
    public void onStartScreen() {
        //System.exit(0);
    }

    @Override
    public void onEndScreen() {
    }

    public void showGraphicsOptionsWindow() {
        if (!graphicsOptionsWindow.isVisible()) {
            graphicsOptionsWindow.setVisible(true);
        }
    }

    public void showAudioOptionsWindow() {
        if (!audioOptionsWindow.isVisible()) {
            audioOptionsWindow.setVisible(true);
        }
    }

    public void showCreateRoomPanel() {
        screen.findElementByName("pnlCreateRoom").show();
    }
    
    public void addSampleList(){
        ListBox listNumbers = screen.findNiftyControl(MainScreenBuilder.LB_ROOM_LIST_NUMBER, ListBox.class);
        listNumbers.addItem("52");
        listNumbers.addItem("127");
        listNumbers.addItem("1427");
        ListBox listNames = screen.findNiftyControl(MainScreenBuilder.LB_ROOM_LIST_NAME, ListBox.class);
        listNames.addItem("Room 1");
        listNames.addItem("Room 2");
        listNames.addItem("Room 3");
        ListBox listGameTypes = screen.findNiftyControl(MainScreenBuilder.LB_ROOM_LIST_GAME_TYPE, ListBox.class);
        listGameTypes.addItem("Deathmath");
        listGameTypes.addItem("Team Deathmath");
        listGameTypes.addItem("Survivor");
        ListBox listTeamSize = screen.findNiftyControl(MainScreenBuilder.LB_ROOM_LIST_TEAM_SIZE, ListBox.class);
        listTeamSize.addItem("3x3");
        listTeamSize.addItem("5x5");
        listTeamSize.addItem("8x8");
    }
}
